package com.engine.cn.configuration;

import com.engine.cn.service.CustomService;
import org.springframework.boot.autoconfigure.AutoConfiguration;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;

@AutoConfiguration
// 当类路径存在MyService时生效
@ConditionalOnClass(CustomService.class) // 当类路径存在CustomService时生效
@EnableConfigurationProperties(CustomProperties.class) // 启用配置属性
public class MyAutoConfiguration {

    @Bean
    @ConditionalOnMissingBean // 当容器中不存在该Bean时创建
    public CustomService customService(CustomProperties properties) {
        return new CustomService(properties);
    }
}
